import qs from 'qs'
// 使用 Mock
const Mock = require('mockjs')

Mock.setup({
  timeout: '500-1000'
})

// my/test
Mock.mock(/\/my\/test/, 'get', () => {
  const arr = []
  for (let i = 0; i < 10; i++) {
    arr.push(
      Mock.mock({
        id: '@id',
        name: '@ctitle(2,4)'
      })
    )
  }
  return { msg: '获取成功', result: arr }
})

// 模拟 我的收藏
Mock.mock(/\/member\/collect/, 'get', config => {
  const queryString = config.url.split('?')[1]
  const queryObject = qs.parse(queryString)
  const items = []
  for (let i = 0; i < +queryObject.pageSize; i++) {
    items.push(
      Mock.mock({
        id: '@id',
        name: '@ctitle(10,20)',
        desc: '@ctitle(4,10)',
        price: '@float(100,200,2,2)',
        picture: `http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_${Mock.mock(
          '@integer(1,8)'
        )}.jpg`
      })
    )
  }

  return {
    msg: '获取收藏商品成功',
    result: {
      count: 35,
      pageSize: +queryObject.pageSize,
      page: +queryObject.page,
      items
    }
  }
})
